#include "mainwidget.h"
#include "devicesform.h"
#include "headerform.h"
#include "individualdisplayform.h"
#include "logform.h"
#include "videowallform.h"
#include "layoutsettingsform.h"
#include "logindialog.h"

#include <QStyleOption>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPainter>

MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    m_pLoginDialog(new LoginDialog)
{
    setObjectName("MainWidget");
    initUI();
    initConnects();
}

MainWidget::~MainWidget()
{
}

void MainWidget::run()
{
    //首先检查数据库中admin项有没有密码
    //    this->show();
    this->showMaximized();
    //    m_pLoginDialog->exec();
}

void MainWidget::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

void MainWidget::slotMenuSettings()
{
    m_pToolsForm->move(11,60);
    m_pToolsForm->resize(width()-22,120);
    m_pToolsForm->setVisible(!m_pToolsForm->isVisible());

    m_pToolsForm->raise();
}

void MainWidget::slotMenuHelp()
{

}

void MainWidget::initUI()
{
    m_pToolsForm=new ToolsForm(this);
    m_pToolsForm->setObjectName("m_pToolsForm");
    m_pToolsForm->move(0,50);
    m_pToolsForm->setVisible(false);

    m_pHeaderForm=new HeaderForm;
    m_pHeaderForm->setFixedHeight(45);

    m_pDevicesForm=new DevicesForm ;
    m_pDevicesForm->setFixedWidth(180);
    m_pIndividualDisplayForm=new IndividualDisplayForm;
    m_pIndividualDisplayForm->setFixedWidth(180);

    m_pLayoutSettingsForm=new LayoutSettingsForm;
    //    m_pLayoutSettingsForm->setStyleSheet("background:yellow");
    m_pLogForm=new LogForm;
    m_pLogForm->setFixedHeight(80);
    m_pVideoWallForm=new VideoWallForm;

    QHBoxLayout *videoLayout=new QHBoxLayout;
    videoLayout->setMargin(0);
    //    videoLayout->setSpacing(0);
    //    videoLayout->addWidget(w);
    videoLayout->addWidget(m_pVideoWallForm,1);
    videoLayout->addWidget(m_pIndividualDisplayForm);

    m_pVideoWallForm->setStyleSheet("background:gray");
    //    m_pIndividualDisplayForm->setStyleSheet("background:yellow");

    //    setLayout(videoLayout);

    QVBoxLayout *layoutVLayout=new QVBoxLayout;
    layoutVLayout->setMargin(0);
    layoutVLayout->addWidget(m_pLayoutSettingsForm);
    layoutVLayout->addLayout(videoLayout,1);
    layoutVLayout->addWidget(m_pLogForm);

    //    setLayout(layoutVLayout);

    QHBoxLayout *devicesLayout=new QHBoxLayout;
    devicesLayout->setMargin(0);
    devicesLayout->addWidget(m_pDevicesForm);
    devicesLayout->addLayout(layoutVLayout,1);

    //setLayout(devicesLayout);

    QVBoxLayout *headerVLayout=new QVBoxLayout;
    //    headerVLayout->setMargin(0);
    //    headerVLayout->setSpacing(0);
    headerVLayout->addWidget(m_pHeaderForm);
    headerVLayout->addLayout(devicesLayout,1);

    setLayout(headerVLayout);
}

void MainWidget::initConnects()
{
    connect(m_pHeaderForm,SIGNAL(sigSettings()),
            this,SLOT(slotMenuSettings()));
}
